<style>
    .welcome .layui-card {border:1px solid #f2f2f2;border-radius:5px;}
    .welcome .icon {margin-right:10px;color:#1aa094;}
    .welcome .icon-cray {color:#ffb800 !important;}
    .welcome .icon-blue {color:#1e9fff !important;}
    .welcome .icon-tip {color:#ff5722 !important;}
    .welcome .layuimini-qiuck-module {text-align:center;margin-top:10px}
    .welcome .layuimini-qiuck-module a i {display:inline-block;width:100%;height:60px;line-height:60px;text-align:center;border-radius:2px;font-size:30px;background-color:#F8F8F8;color:#333;transition:all .3s;-webkit-transition:all .3s;}
    .welcome .layuimini-qiuck-module a cite {position:relative;top:2px;display:block;color:#666;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;font-size:14px;}
    .welcome .welcome-module {width:100%;}
    .welcome .panel {background-color:#fff;border:1px solid transparent;border-radius:3px;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.05);box-shadow:0 1px 1px rgba(0,0,0,.05)}
    .welcome .panel-body {padding:10px}
    .welcome .panel-title {margin-top:0;margin-bottom:0;font-size:12px;color:inherit}
    .welcome .label {display:inline;padding:.5em .6em .3em;font-size:75%;font-weight:700;line-height:1;color:#fff;text-align:center;white-space:nowrap;vertical-align:baseline;border-radius:.25em;margin-top:.3em;}
    .welcome .layui-red {color:red}
    .welcome .main_btn > p {height:40px;}
    .welcome .layui-bg-number {background-color:#F8F8F8;}
</style>
<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main welcome">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-row layui-col-space15">
                    <div class="layui-col-md12">
                        <div class="layui-card">
                            <div class="layui-card-header"><i class="fa fa-warning icon"></i>基础数据</div>
                            <div class="layui-card-body">
                                <div class="welcome-module">
                                    <div class="layui-row layui-col-space10">
                                        <div class="layui-col-xs3">
                                            <div class="panel layui-bg-number">
                                                <div class="panel-body">
                                                    <div class="panel-title">
                                                        <span class="label pull-right layui-bg-blue">实时</span>
                                                        <h5>总链接数</h5>
                                                    </div>
                                                    <div class="panel-content">
                                                        <h1 class="no-margins" id="urlQuantity">1234</h1>
                                                        <small>当前分类总记录数</small>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="layui-col-xs3">
                                            <div class="panel layui-bg-number">
                                                <div class="panel-body">
                                                    <div class="panel-title">
                                                        <span class="label pull-right layui-bg-cyan">实时</span>
                                                        <h5>总访问量</h5>
                                                    </div>
                                                    <div class="panel-content">
                                                        <h1 class="no-margins" id="accessQuantity">1234</h1>
                                                        <small>当前分类总记录数</small>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="layui-col-xs3">
                                            <div class="panel layui-bg-number">
                                                <div class="panel-body">
                                                    <div class="panel-title">
                                                        <span class="label pull-right layui-bg-orange">实时</span>
                                                        <h5>今日访问量</h5>
                                                    </div>
                                                    <div class="panel-content">
                                                        <h1 class="no-margins" id="todayAccessQuantity">1234</h1>
                                                        <small>当前分类总记录数</small>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="layui-col-xs3">
                                            <div class="panel layui-bg-number">
                                                <div class="panel-body">
                                                    <div class="panel-title">
                                                        <span class="label pull-right layui-bg-green">实时</span>
                                                        <h5>今日独立IP数</h5>
                                                    </div>
                                                    <div class="panel-content">
                                                        <h1 class="no-margins" id="todayIpQuantity">1234</h1>
                                                        <small>当前分类总记录数</small>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <div class="layui-card">
                            <div class="layui-card-header"><i class="fa fa-line-chart icon"></i>七日访问量条形图</div>
                            <div class="layui-card-body">
                                <div id="echarts-1" style="width: 100%;min-height: 380px"></div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <div class="layui-card">
                            <div class="layui-card-header"><i class="fa fa-line-chart icon"></i>七日访问量趋势图</div>
                            <div class="layui-card-body">
                                <div id="echarts-2" style="width: 100%;min-height: 380px"></div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-col-md12">
                        <div class="layui-card">
                            <div class="layui-card-header"><i class="fa fa-line-chart icon"></i>今日访问量Top25</div>
                            <div class="layui-card-body">
                                <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['layer', 'echarts', 'table'], function () {
        var $ = layui.jquery,
            layer = layui.layer,
            table = layui.table,
            echarts = layui.echarts;

        AjaxUtil.get({
            url: '/tenant/dashboard/quantity',
            success: function (res) {
                if (res.code == '0') {
                    // 刷新数据
                    $("#urlQuantity").text(res.data.urlQuantity);
                    $("#accessQuantity").text(res.data.accessQuantity);
                    $("#todayAccessQuantity").text(res.data.todayAccessQuantity);
                    $("#todayIpQuantity").text(res.data.todayIpQuantity);
                } else {
                    layer.msg(res.msg, {time: 1000, icon: 2});
                }
            }
        });

        var currTable = table.render({
            elem: '#currentTableId',
            url: '/tenant/dashboard/topList',
            method: 'get',
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code,
                    "msg": res.msg,
                    "data": res.data
                };
            },
            defaultToolbar: ['filter', 'exports', 'print'],
            cols: [[
                {type: 'numbers', width: '5%', title: '#', align: 'center'},
                {field: 'surl', width: '10%', title: '短链', align: 'center'},
                {field: 'createdAt', width: '20%', title: '创建时间'},
                {field: 'lurl', width: '45%', title: '原始链接'},
                {field: 'accessCount', width: '10%', title: '访问量'},
                {field: 'ipCount', width: '10%', title: '独立IP数'}
            ]],
            skin: 'line'
        });


        /**
         * echarts报表功能
         */
        var echartsRecords1 = echarts.init(document.getElementById('echarts-1'), 'walden');
        var echartsRecords2 = echarts.init(document.getElementById('echarts-2'), 'walden');

        AjaxUtil.get({
            url: '/tenant/dashboard/chartsInfo',
            success: function (res) {
                if (res.code == '0') {
                    var dayList = res.data.dayList;
                    var dataList = res.data.dataList;

                    // 刷新数据
                    var optionRecords = {
                        tooltip: {
                            trigger: 'axis'
                        },
                        legend: {
                            data: ['访问次数']
                        },
                        grid: {
                            left: '3%',
                            right: '4%',
                            bottom: '3%',
                            containLabel: true
                        },
                        toolbox: {
                            feature: {
                                saveAsImage: {}
                            }
                        },
                        xAxis: {
                            data: dayList
                        },
                        yAxis: {},
                        series: [
                            {
                                name: '访问次数',
                                type: 'bar',
                                data: dataList,
                            }
                        ]
                    };
                    echartsRecords1.setOption(optionRecords);


                    optionRecords = {
                        tooltip: {
                            trigger: 'axis'
                        },
                        legend: {
                            data: ['访问次数']
                        },
                        grid: {
                            left: '3%',
                            right: '4%',
                            bottom: '3%',
                            containLabel: true
                        },
                        toolbox: {
                            feature: {
                                saveAsImage: {}
                            }
                        },
                        xAxis: {
                            type: 'category',
                            boundaryGap: false,
                            data: dayList
                        },
                        yAxis: {
                            type: 'value'
                        },
                        series: [
                            {
                                name: '访问次数',
                                type: 'line',
                                data: dataList
                            },
                        ]
                    };
                    echartsRecords2.setOption(optionRecords);
                } else {
                    layer.msg(res.msg, {time: 1000, icon: 2});
                }
            }
        });

        // echarts 窗口缩放自适应
        window.onresize = function () {
            echartsRecords1.resize();
            echartsRecords2.resize();
        }
    });
</script>
